package ua.dp.mzav.train.tm.model;

/** Enumerates all allowed states of request.
 *
 * The following diagram illustrates the common life cycle of Leave request. 
 * @image LeaveRequestActions.emf
 */
public enum LeaveRequestActions
{
   /** Initial state of the request - it is just created and should be approved.
    * The request is not "active".
    * Supervisor approval is required.
    */
   REQUESTED(0),

   /// A final state of request when it is rejected by Supervisor.
   SUPERVISOR_REJECTED(1),

   /// Request is approved by Supervisor - Manager approval is required.
   SUPERVISOR_APPROVED(2),

   /// A final state of request when it is rejected by Manager.
   MANAGER_REJECTED(3),

   /// Request is approved by Manager - the Request is "active".
   MANAGER_APPROVED(4),

   /** Emloyee cancels Request that has been approved by Superviser.
    * The Request is still "active" - until final approval.
    */
   CANCEL_REQUESTED(5),

   /** Request is cancelled by Supervisor.
    * The Request returns in it's usual "active" state.
    */
   CANCEL_SUPERVISOR_REJECTED(6),

   /// Request is approved by Supervisor - Manager approval is required.
   CANCEL_SUPERVISOR_APPROVED(7),

   /** Request is cancelled by Manager.
    * The Request returns in it's usual "active" state.
    */
   CANCEL_MANAGER_REJECTED(8),
   
   /** Request is cancelled.
    * It is not "active".
    */
   CANCEL_MANAGER_APPROVED(-1);

   
   /** ID of every "active" state is greater than ID of any not "active" state.
    */
   private final byte id;
   

   
   LeaveRequestActions(final int anId)
   {
      id = (byte) anId;
   }
   
   /** Binary representation of the state.
    * 
    * @return A byte value.
    */
   final byte getId()
   {
      return id;
   }
   
   /** Verifies if Request is active if its last history action is equal to this one.
    * 
    * "Active" means that the request has full approval and
    * actually affects working calendar of Employee.
    * 
    * "Not active" means that:
    * - Request does not have full approval (is in processing)
    * - Request is rejected
    * - Request is cancelled
    * 
    * In all cases it is out of scope of working calendar of Employee.
    */
   public final boolean isActive()
   {
      return (id >= MANAGER_APPROVED.getId());
   }
}
